package com.orm.analysis.dao.impl;

import com.orm.analysis.dao.GenericJPADAO;
import com.orm.analysis.model.Check;
import com.orm.analysis.model.CreditCard;
import com.orm.analysis.model.CustOrder;
import com.orm.analysis.model.Payment;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Query;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: saman
 * Date: 11/8/13
 * Time: 6:23 PM
 * To change this template use File | Settings | File Templates.
 */
public class CreditCardDAO extends GenericJPADAO<CreditCard, Integer> {

       public List<CreditCard> list(int page, int size) {
           Query query = this.em.createQuery("Select a from Payment a where a.paymentType=:paymode");
           query.setParameter("paymode","CREDIT_CARD");
           query.setFirstResult((page - 1) * size);
           query.setMaxResults(size);
           return query.getResultList();
       }


       public CreditCard getById(Integer id) {
             return this.em.find(CreditCard.class,id);
       }

    @Transactional
                 @Override
                 public void save(CreditCard entity) {
                      getEntityManager().persist(entity);
                 }

    @Transactional
                 @Override
                     public void delete(Object id) {
                         getEntityManager().remove(getEntityManager().find(CreditCard.class, id));

                      }
}
